import Mock from 'mockjs'
import loginAPI from './login'
import majorAPI from './major'
import studentAPI from './student'
import vodAPI from './courseVod'
import liveAPI from './courseLive'
import learnProcessAPI from './studentLearnProcess'
import schoolAPI from './school'

// import userAPI from './user'

// 修复在使用 MockJS 情况下，设置 withCredentials = true，且未被拦截的跨域请求丢失 Cookies 的问题
// https://github.com/nuysoft/Mock/issues/300
Mock.XHR.prototype.proxy_send = Mock.XHR.prototype.send
Mock.XHR.prototype.send = function() {
  if (this.custom.xhr) {
    this.custom.xhr.withCredentials = this.withCredentials || false
  }
  this.proxy_send(...arguments)
}

// 延时350-600毫秒请求到数据
Mock.setup({
  timeout: '100-200'
})

// 登录相关
Mock.mock(/\/api\/login/, 'post', loginAPI.login)
Mock.mock(/\/api\/logout/, 'post', loginAPI.logout)
Mock.mock(/\/api\/student\/profile/, 'get', studentAPI.getStudentInfo)
Mock.mock(/\/api\/student\/learn-plan/, 'get', studentAPI.getLearnPlan)

// 专业分类
Mock.mock(/\/admin\/major\/list/, 'get', majorAPI.getMajors)
Mock.mock(/\/admin\/major\/save/, 'post', majorAPI.addMajor)
Mock.mock(/\/admin\/major\/update/, 'post', majorAPI.updateMajor)
Mock.mock(/\/admin\/major\/state\/update/, 'post', majorAPI.updateStatus)

// 课程点播
Mock.mock(/\/api\/course\/page/, 'get', vodAPI.getVods)
Mock.mock(/\/api\/course\/progress\/update/, 'post', vodAPI.getVods)

// 直播
Mock.mock(/\/api\/live-course\/page/, 'get', liveAPI.getLives)
Mock.mock(/\/api\/live-course\/sign-in/, 'post', liveAPI.getLives)
Mock.mock(/\/api\/live-course\/state/, 'post', liveAPI.getCourseStatus)
Mock.mock(/\/api\/message\/list/, 'get', liveAPI.getMessageList)

// 学生学习进度
Mock.mock(/\/admin\/learnProcess\/list/, 'get', learnProcessAPI.getLearnProcessList)

// 教务公告
Mock.mock(/\/api\/notice\/page/, 'get', schoolAPI.getSchoolNotices)
Mock.mock(/\/api\/notice\/[0-9]/, 'get', schoolAPI.getNoticeDetail)
Mock.mock(/\/api\/banner\/list/, 'get', schoolAPI.getBannerList)

export default Mock
